from django.shortcuts import render
from rest_framework.viewsets import ReadOnlyModelViewSet
from .serializers import AreaSerializer,SubAreaSerializer

# Create your views here.
from areas.models import Area
from rest_framework_extensions.cache.mixins import CacheResponseMixin


class AreasViewSet(CacheResponseMixin,ReadOnlyModelViewSet):
    pagination_class = None  # 区划信息不分页

    def get_queryset(self):
        """
        提供数据集
        """
        if self.action == 'list':
            return Area.objects.filter(parent=None)
        else:
            return Area.objects.all()

    # serializer_class = AreaSerializer
    def get_serializer_class(self):
        if self.action == 'list':
            return AreaSerializer
        else:
            return SubAreaSerializer